home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / cdedit / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  9.2 KB  |  281 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/cdEdit/RCS/timer.c,v 2.0 91/10/06 21:01:59 chua Exp $ */
  25. /* $Log:    timer.c,v $
  26.  * Revision 2.0  91/10/06  21:01:59  chua
  27.  * Update to version 2.0
  28.  * 
  29.  * Revision 1.13  91/09/10  15:56:02  chua
  30.  * Changed some code in UpdateTime so that currentTrack will not be
  31.  * set to track if the player is in stop mode.  This was causing an error when
  32.  * we search to the last track from rest, and the track duration field
  33.  * would not be updated.
  34.  * 
  35.  * Revision 1.12  91/09/05  17:52:44  chua
  36.  * In TimerNotify, check to see if there is a need to highlight either the play or
  37.  * pause button in green, depending on the mode that the player is in.
  38.  * 
  39.  * Revision 1.11  91/09/03  15:29:04  chua
  40.  * Added the copyright header.
  41.  * 
  42.  * Changed the constants from all capitalized to initial capitalized only.
  43.  * 
  44.  * In TimerNotify, if there is currently no disc (playerState == Nothing), check to see
  45.  * if a disc has been inserted by calling InitializeCD.
  46.  * 
  47.  * Added the menu handlers for the relative time and absolute time menu items (found under
  48.  * the options menu).
  49.  * 
  50.  * Revision 1.1  91/07/09  16:49:00  chua
  51.  * 
  52.  * 
  53.  * Revision 1.0  91/07/08  13:46:43  chua
  54.  * Initial revision
  55.  *  */
  56.  
  57. static char timerrcsid[] = "$Header: /Source/Media/collab/cdEdit/RCS/timer.c,v 2.0 91/10/06 21:01:59 chua Exp $";
  58.  
  59. #include "main.h"
  60.  
  61. static int timetype = Relative;
  62. static currentTrack = -1;
  63. static flag = 0;
  64.  
  65. /* 
  66.  * This function will update the time display field on the remote control, depending on the value of the parameter, time, passed to it.
  67.  * If time = Current, the current playing time on the CD is displayed.
  68.  * If time = Whole, the total length of the CD is displayed.
  69.  * If time = Clear, the time display field is set to all zeros.
  70.  * The duration slider will also be updated, if the user is not currently dragging the slider (when playerState != Duration).
  71.  */
  72. void UpdateTime(time)
  73.      int time;
  74. {
  75.   int track, min, sec, frame;
  76.   int durationMin, durationSec;
  77.   char t[17], m[12], d[5], s[5];
  78.   Msf duration;
  79.   
  80.   if (time == Current)                            /* Display the current playing time on the CD */
  81.   {
  82.     if (timetype == Absolute)                        /* Get absolute time information */
  83.     {
  84.       cdrom_get_absinfo(fd, &track, &min, &sec, &frame);
  85.     }
  86.     else                                /* Get relative time information */
  87.     {
  88.       cdrom_get_relinfo(fd, &track, &min, &sec, &frame);
  89.     }
  90.   }
  91.   else if (time == Whole)                        /* Display the total time and number of tracks in the CD */
  92.   {
  93.     currentTrack = -1;
  94.     track = numTracks;
  95.     sprintf(t, "Total tracks : %02d", track);
  96.     min = toc->total_msf->min;
  97.     sec = toc->total_msf->sec;
  98.   }
  99.   else 
  100.   {
  101.     track = 0;                                /* Set the time to all zeros.  Disc has been ejected. */
  102.     min = 0;
  103.     sec = 0;
  104.   }
  105.   sprintf(m, "Time : %02d:%02d", min, sec);
  106.   durationMin = 0;
  107.   durationSec = 0;
  108.   if (time == Current) 
  109.   {
  110.     if (timetype == Relative)                        /* Get the duration of the track, in order to update */
  111.     {                                    /* the duration slider later (if necessary) */
  112.       duration = get_track_duration(toc, track);
  113.       if (duration != NULL) 
  114.       {
  115.     durationMin = duration->min;
  116.     durationSec = duration->sec;
  117.       }
  118.     }
  119.     else 
  120.     {
  121.       durationMin = toc->total_msf->min;                /* Set the duration to the disc duration (absolute duration) */
  122.       durationSec = toc->total_msf->sec;
  123.     }
  124.   }
  125.   if (time != Current)                            /* min, sec is now used to update the duration time display.  They will only */
  126.   {                                    /* be relevant if time == Current, else they are set to zero. */
  127.     min = 0;
  128.     sec = 0;
  129.   }
  130.   xv_set(cdEdit_window1->TimeMsg,                    /* Update the time display field */
  131.      PANEL_LABEL_STRING, m,
  132.      NULL);
  133.   if (track != currentTrack || timetype != displayType)            /* Update the track and time display if either the track varies or  */
  134.   {                                    /* the display time varies (whether absolute or relative) */
  135.     if (timetype == Relative)                        /* Set the label for the duration slider */
  136.     {
  137.       xv_set(cdEdit_window1->DurationLabelMsg,
  138.          PANEL_LABEL_STRING, "Track Duration",
  139.          NULL);
  140.     }
  141.     else 
  142.     {
  143.       xv_set(cdEdit_window1->DurationLabelMsg,
  144.          PANEL_LABEL_STRING, "Disc Duration",
  145.          NULL);
  146.     }
  147.     if (time != Whole)                            /* Update the track display field */
  148.     {
  149.       sprintf(t, "Track : %02d", track);
  150.     }
  151.     xv_set(cdEdit_window1->TotalTracksMsg,
  152.        PANEL_LABEL_STRING, t,
  153.        NULL);
  154.     if (time == Current) 
  155.     {
  156.       xv_set(cdEdit_window1->DurationSlider,                /* Set the min, max range for the duration slider */
  157.          PANEL_MIN_VALUE, 0,
  158.          PANEL_MAX_VALUE, durationSec + durationMin*60,
  159.          NULL);
  160.       sprintf(d, "%02d:%02d", durationMin, durationSec);
  161.       currentTrack = track;                        /* Set the global flags to the current values */
  162.     }
  163.     else                                /* Ignore the duration slider since we are not in play mode */
  164.     {
  165.       sprintf(d, "00:00");
  166.     }
  167.     xv_set(cdEdit_window1->DurationTimeMsg,                /* Set the duration slider time (either track duration or disc duration) */
  168.        PANEL_LABEL_STRING, d,
  169.        NULL);
  170.     displayType = timetype;                        /* Keeps track of whether the player is in relative or absolute mode */
  171.   }
  172.   if (playerState != DurationMode) 
  173.   {
  174.     xv_set(cdEdit_window1->DurationSlider,                /* Set the duration slider to the correct position */
  175.        PANEL_VALUE, sec + min*60,
  176.        NULL);
  177.     sprintf(s, "%02d:%02d", min, sec);
  178.     xv_set(cdEdit_window1->TempDurationMsg,                /* Update the duration slider time display */
  179.        PANEL_LABEL_STRING, s,
  180.        NULL);
  181.   }
  182. }
  183.  
  184. /*
  185.  * This is the timer notify function that is called every second.
  186.  * First, it checks if there is a need to hightlight the play or pause button in green, depending on what mode the player is in.
  187.  * It will then either update the time display field with the current time, or show the total duration time of the disc, depending on which state the
  188.  * CD player is in.  It calls the function UpdateTime (see above) to do the updating.
  189.  */
  190. Notify_value TimerNotify()
  191. {
  192.   int track;
  193.   
  194.   if ((cdrom_playing(fd, &track) || playerState == PauseMode) && flag) /* Highlight the play button in green or black (alternating) */
  195.   {
  196.     xv_set(cdEdit_window1->PlayButton, PANEL_ITEM_COLOR, gcm_color_index("green"), NULL);
  197.     if (playerState != PauseMode) 
  198.     {
  199.       xv_set(cdEdit_window1->PauseButton, PANEL_ITEM_COLOR, gcm_color_index("black"), NULL);
  200.     }
  201.     flag = 0;
  202.   }
  203.   else if (playerState == PauseMode) 
  204.   {
  205.     xv_set(cdEdit_window1->PlayButton, PANEL_ITEM_COLOR, gcm_color_index("black"), NULL);
  206.     xv_set(cdEdit_window1->PauseButton, PANEL_ITEM_COLOR, gcm_color_index("green"), NULL);
  207.     if (flag) 
  208.       flag = 0;
  209.     else
  210.       flag = 1;
  211.   }
  212.   else 
  213.   {
  214.     xv_set(cdEdit_window1->PlayButton, PANEL_ITEM_COLOR, gcm_color_index("black"), NULL);
  215.     xv_set(cdEdit_window1->PauseButton, PANEL_ITEM_COLOR, gcm_color_index("black"), NULL);
  216.     flag = 1;
  217.   }
  218.   if (cdrom_playing(fd, &track) ||                    /* CD player is currently playing.  Update the current time. */
  219.       playerState == PauseMode || playerState == DurationMode)        /* CD player is in pause mode, or user is currently dragging the slider bar */
  220.   {                                    /* whether CD is playing.  Also update the current time */
  221.     UpdateTime(Current);
  222.   }
  223.   else if (playerState == Nothing)                    /* Clear the time display */
  224.   {
  225.     UpdateTime(Clear);
  226.     InitializeCD();                            /* Check if a disc has been inserted */
  227.   }
  228.   else                                    /* Player is in stop mode.  Show the total time of the disc */
  229.   {
  230.     UpdateTime(Whole);
  231.     playerState = StopMode;
  232.   }    
  233.   return NOTIFY_DONE;
  234. }
  235.  
  236.  
  237. /*
  238.  * Menu handler for `DisplayTimeMenu (Relative)'.
  239.  */
  240. Menu_item RelativeTimeHandler(item, op)
  241.      Menu_item    item;
  242.      Menu_generate    op;
  243. {
  244.   switch (op) 
  245.   {
  246.    case MENU_DISPLAY:
  247.     break;
  248.    case MENU_DISPLAY_DONE:
  249.     break;
  250.    case MENU_NOTIFY:
  251.     timetype = Relative;
  252.     break;
  253.    case MENU_NOTIFY_DONE:
  254.     break;
  255.   }
  256.   return item;
  257. }
  258.  
  259. /*
  260.  * Menu handler for `DisplayTimeMenu (Absolute)'.
  261.  */
  262. Menu_item AbsoluteTimeHandler(item, op)
  263.      Menu_item    item;
  264.      Menu_generate    op;
  265. {
  266.   switch (op) 
  267.   {
  268.    case MENU_DISPLAY:
  269.     break;
  270.    case MENU_DISPLAY_DONE:
  271.     break;
  272.    case MENU_NOTIFY:
  273.     timetype = Absolute;
  274.     break;
  275.    case MENU_NOTIFY_DONE:
  276.     break;
  277.   }
  278.   return item;
  279. }
  280.  
  281.